﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlTypes;

namespace Quản_Lý_Thư_Viện
{
    class PTSDataAccess
    {
        private DataProvider _provider = new DataProvider();
        public PTSDataAccess()
        {
            _provider.connect();
        }
        int i;
        DataTable dt = new DataTable();
        public void insertPTS(PTSinfo info)
        {
            dt = laytatcapts();
            i = dt.Rows.Count;
            string ngaytra = info.Ngtra.Value.Month + "/" + info.Ngtra.Value.Day + "/" + info.Ngtra.Value.Year+" " + info.Ngtra.Value.Hour + ":" + info.Ngtra.Value.Minute + ":" + info.Ngtra.Value.Second;
            string insertCommand = "insert into dbo.PHIEUTRASACH values('PTS" + i + "','" + info.Manv
                + "','" + info.Madg + "','" + info.Trigiapts + "','" + ngaytra + "')";
            _provider.executeNonQuery(insertCommand);
        }
        public DataTable laydspts()
        {
            return _provider.GetData("Select * from dbo.PHIEUTRASACH");
        }
        public DataTable laymapts()
        {

            string today = DateTime.Today.Year + "/" + DateTime.Today.Month + "/" + DateTime.Today.Day;
            return _provider.GetData("select MAPTS from dbo.PHIEUTRASACH WHERE MADG = '"+frmPhieuTraSach.madg1+"' and NGTRA = '"+today+"'");
        }
        public DataTable laytatcapts()
        {
            return _provider.GetData("select * from dbo.PHIEUTRASACH ");
        }
        public void deletepts(PTSinfo info)
        {
            CT_PTScontrol ctcontrol = new CT_PTScontrol();
            ctcontrol.deleteptsvactpts();
            string deleteCommand = "Delete from dbo.PHIEUTRASACH where MADG ='" + info.Madg + "'";
            _provider.executeNonQuery(deleteCommand);
        }
    }
}
